package com.gary.mat;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * -XX:+HeapDumpBeforeFullGC -XX:HeapDumpPath=D:\Document\Desktop\学习\hprof\student.hprof
 * @author peng_rui
 * @date 2022/3/13
 */
public class StudentDemo {
    private static List<WebWorking> webList = new ArrayList<>();

    public static void addWeb() {
        for (int i = 0; i < 100; i++) {
            WebWorking webWorking = new WebWorking();
            webWorking.setUrl("www." + i + ".com");
            webList.add(webWorking);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        addWeb();
        Student zhangsan = new Student("张三", 1, new ArrayList<>());
        Student lisi = new Student("李四", 2, new ArrayList<>());
        Student wangwu = new Student("王五", 3, new ArrayList<>());

        zhangsan.equals(lisi);
        Thread.sleep(5000);
        for (int i = 0; i < webList.size(); i++) {
            Thread.sleep(500);
            if (i % 3 == 0) {
                zhangsan.viewWeb(webList.get(i));
            }
            if (i % 5 == 0) {
                lisi.viewWeb(webList.get(i));
            }
            if (i % 7 == 0) {
                wangwu.viewWeb(webList.get(i));
            }
        }

        webList.clear();
        System.gc();
    }
}


@Data
@AllArgsConstructor
@NoArgsConstructor
class Student {
    private String name;
    private int sid;
    private List<WebWorking> webs;

    public void viewWeb(WebWorking webW) {
        webs.add(webW);
    }
}

@Data
class WebWorking {
    private String url;
}